package com.originskyseed.platform.user.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.originskyseed.platform.core.tenant.util.TenantCodeUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Component;

import com.originskyseed.platform.core.base.BasePage;
import com.originskyseed.platform.core.util.bean.PrimaryKeyGeneratorUtil;
import com.originskyseed.platform.user.mapper.PlayerRelateViewLiveStateMapper;
import com.originskyseed.platform.user.model.PlayerRelateViewLiveState;
import com.originskyseed.platform.user.service.IPlayerRelateViewLiveStateService;

/**
 * 玩家观看直播状态信息表Service接口实现类（OSI_PLAYER_RELATE_VIEW_LIVE_STATE）
 * 
 * @author Tangwanghui
 */
@DubboService
@Component("playerRelateViewLiveStateService")
public class PlayerRelateViewLiveStateServiceImpl implements IPlayerRelateViewLiveStateService {

	@Resource
	private PlayerRelateViewLiveStateMapper playerRelateViewLiveStateMapper;

	/**
	 * 删除记录
	 * 
	 * @param id
	 * @return
	 * @throws Exception
	 */
	@Override
	public int deleteByPrimaryKey(String id) throws Exception {
		return this.playerRelateViewLiveStateMapper.deleteByPrimaryKey(id);
	}

	/**
	 * 批量删除记录
	 * 
	 * @param ids
	 * @return
	 * @throws Exception
	 */
	@Override
	public int deleteByPrimaryKeys(List<String> ids) throws Exception {
		return this.playerRelateViewLiveStateMapper.deleteByPrimaryKeys(ids);
	}

	/**
	 * 插入记录
	 * 
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int insert(PlayerRelateViewLiveState record) throws Exception {
		if (StringUtils.isBlank(record.getId())) {
			record.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
		}
		record.setCreateTime(new Date());
		return this.playerRelateViewLiveStateMapper.insert(record);
	}

	/**
	 * 插入记录（仅非空值字段）
	 * 
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int insertSelective(PlayerRelateViewLiveState record) throws Exception {
		if (StringUtils.isBlank(record.getId())) {
			record.setId(PrimaryKeyGeneratorUtil.getInstance().getRandomKey());
		}
		record.setCreateTime(new Date());
		return this.playerRelateViewLiveStateMapper.insertSelective(record);
	}

	/**
	 * 更新记录
	 * 
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int updateByPrimaryKey(PlayerRelateViewLiveState record) throws Exception {
		record.setUpdateTime(new Date());
		return this.playerRelateViewLiveStateMapper.updateByPrimaryKey(record);
	}

	/**
	 * 更新记录（仅非空值字段）
	 * 
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public int updateByPrimaryKeySelective(PlayerRelateViewLiveState record) throws Exception {
		record.setUpdateTime(new Date());
		return this.playerRelateViewLiveStateMapper.updateByPrimaryKeySelective(record);
	}

	/**
	 * 查询记录
	 * 
	 * @param id
	 * @return
	 * @throws Exception
	 */
	@Override
	public PlayerRelateViewLiveState selectByPrimaryKey(String id) throws Exception {
		return this.playerRelateViewLiveStateMapper.selectByPrimaryKey(id);
	}

	/**
	 * 查询列表
	 * 
	 * @param record
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<PlayerRelateViewLiveState> selectList(PlayerRelateViewLiveState record) throws Exception {
		return this.playerRelateViewLiveStateMapper.selectList(record);
	}

	/**
	 * 分页查询列表
	 * 
	 * @param params
	 * @param page
	 * @return
	 * @throws Exception
	 */
	@Override
	public BasePage<PlayerRelateViewLiveState> selectListByPage(Map<String, Object> params, BasePage<PlayerRelateViewLiveState> page) throws Exception {
		params.put("page", page);
		List<PlayerRelateViewLiveState> list = this.playerRelateViewLiveStateMapper.selectListByPage(params);
		page.setResults(list);
		return page;
	}

	/**
	 * 批量插入
	 *
	 * @param list
	 * @return
	 * @throws Exception
	 */
	public int insertBatch(List<PlayerRelateViewLiveState> list) throws Exception {
		return this.playerRelateViewLiveStateMapper.insertBatch(list);
	}

	/**
	 * 批量插入
	 *
	 * @param list
	 * @return
	 * @throws Exception
	 */
	@Override
	public int insertBatch(String tenantCode,List<PlayerRelateViewLiveState> list) throws Exception {
		if(tenantCode!=null&&StringUtils.isNotBlank(tenantCode))
		{
			TenantCodeUtil.getInstance().createServerTenantCode(tenantCode);
		}
		return this.playerRelateViewLiveStateMapper.insertBatch(list);
	}

	/**
	 * 查询liveId和状态查询是否存在
	 * 
	 * @param list
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<PlayerRelateViewLiveState> selectLiveIds(String tenantCode,List<PlayerRelateViewLiveState> list) throws Exception {
		if(tenantCode!=null&&StringUtils.isNotBlank(tenantCode))
		{
			TenantCodeUtil.getInstance().createServerTenantCode(tenantCode);
		}
		return this.playerRelateViewLiveStateMapper.selectLiveIds(list);
	}


	/**
	 * 查询liveId和状态查询是否存在
	 *
	 * @param list
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<PlayerRelateViewLiveState> selectLiveIds(List<PlayerRelateViewLiveState> list) throws Exception
	{
		return this.playerRelateViewLiveStateMapper.selectLiveIds(list);
	}
}